package top.wsuo.controller;

import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import top.wsuo.tool.MailTool;

import top.wsuo.model.Mail;


@WebServlet("/mailsend.do")
public class MailSendAction extends HttpServlet {
    private static final long serialVersionUID = 1L;


    public MailSendAction() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("UTF-8");
        String from = request.getParameter("form");
        String subject = request.getParameter("subject");
        String content = request.getParameter("content");

        Mail mail = new Mail();
        mail.setFrom(from);
        mail.setSubject(subject);
        mail.setContent(content);
        try {
            MailTool.sendMail(mail);
            System.out.println("邮件发送成功");
            response.sendRedirect("home.jsp");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("邮件发送失败");
        }

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        doGet(request, response);
    }

}
